#include "timer5_drv.h"

#if USE_TIMER5
void timer5_drv_init() {

    /* 使能定时器时钟；*/
    rcu_periph_clock_enable(RCU_TIMER5);
    /* 复位定时器；*/
    timer_deinit(TIMER5);
    timer_parameter_struct timerInitPara;
    timer_struct_para_init(&timerInitPara);
    /* 设置预分频器值；*/
    timerInitPara.prescaler = TIMER5_PSC - 1;     // 输入给计数器的时钟频率为1Mhz，周期1us
    /* 设置自动重装载值；*/
    timerInitPara.period = TIMER5_PERIOD - 1;
    timer_init(TIMER5, &timerInitPara);
    /* 使能定时器的计数更新中断；*/
    timer_interrupt_enable(TIMER5, TIMER_INT_UP);
    /* 使能定时器中断和优先级；*/
    nvic_irq_enable(TIMER5_IRQn, TIMER5_IRQ_PRIORITY);
    /* 使能定时器；*/
    timer_enable(TIMER5);

}


void TIMER5_IRQHandler(void) {
    if (timer_interrupt_flag_get(TIMER5, TIMER_INT_FLAG_UP) == SET) {
        timer_interrupt_flag_clear(TIMER5, TIMER_INT_FLAG_UP);
        // ToggleLed(LED1);
        Timer5IterruptCallBackFunc();
    }
}
#endif
